<?php

require_once '../include/common.php';
ignore_user_abort();
set_time_limit(0); 
$file = "cache/upsid.db";
$hs_num = file_get_contents($file);
$hs= $hs_num + 1;
file_put_contents($file, $hs);

function w_upsid($qq,$qpwd){
	$url="http://pt.3g.qq.com/handleLogin?";
	$data="&sid=MTG0_0GBHBj4NQ_HTJSBuO6t&qq=" . $qq . "&pwd=" . base64_decode($qpwd) . "&bid_code=3GQQ&toQQchat=true&login_url=http://pt.3g.qq.com/s?aid=nLoginnew&&q_from=&modifySKey=2&loginType=3&aid=nLoginHandle";
	$str=html_entity_decode(cpost($url,$data));
	preg_match('/<a.*href=("|\').*sid=(.*)\&.*>.*<\/a>/iU',$str,$sid);
	return $sid[2];
}

	
	$upsid_sql = "SELECT `qq`,`qpwd`,`id` FROM `w_qq` WHERE upsid='1' AND zt='0'";
	$upsid_sth = $db->query($upsid_sql);
	$upsid=$upsid_sth->fetchAll();
	foreach ($upsid as $value) {
		$sid=w_upsid($value[qq],$value[qpwd]);
		$sql = "UPDATE `w_qq` SET `sid`='{$sid}',`zt`='1' WHERE qq='{$value[qq]}' AND id='{$value[id]}'";
		$db->exec($sql);
	}
echo 'ok';